package com.arvato.minipro.controller.common;

import java.io.IOException;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.arvato.common.ftp.FtpTool;
import com.arvato.minipro.controller.BaseController;

/**
 * 
 * @author: smallking
 * 
 * @Descibe:图片采用的是vsftpd 上传 在做预览的时候 需要做下跳转处理
 * 
 * @Date: 2018年5月15日  下午6:05:57
 */
@Controller
public class ImgController extends BaseController{
	
	private Logger logger = LoggerFactory.getLogger(ImgController.class);
	@Autowired
	private FtpTool ftpTool;
	
	@RequestMapping(value = "/img")
	public void img(HttpServletResponse resp, String fileName) {
		if(fileName == null) {
			return;
		}
		try {
			ServletOutputStream outputStream = resp.getOutputStream();
			ftpTool.view(outputStream, fileName);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value = "/voice")
	public void voice(@RequestParam("file") MultipartFile file) {
		
		String fileName = ftpTool.uploadFile(file);
		if(fileName == null) {
			logger.info("语音上传失败");
		}else {
			logger.info(fileName);
		}
	}
	
}
